<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>明确REST接口开发的核心任务 | 课程介绍</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../C01-IntroduceToDRF/AboutDRF.html" />
    
    
    <link rel="prev" href="../C01-IntroduceToDRF/DevelopRESTAPIWithDjango.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="1.5"
        data-chapter-title="明确REST接口开发的核心任务"
        data-filepath="C01-IntroduceToDRF/CoreTaskToDevelopRESTAPI.md"
        data-basepath=".."
        data-revision="Mon Jul 23 2018 07:35:48 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-IntroduceToDRF/index.html">
            
                
                    <a href="../C01-IntroduceToDRF/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        引入DjangoRESTframework
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-IntroduceToDRF/SeparatedFrontendAndBackend.html">
            
                
                    <a href="../C01-IntroduceToDRF/SeparatedFrontendAndBackend.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        Web应用模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-IntroduceToDRF/IntroduceToREST.html">
            
                
                    <a href="../C01-IntroduceToDRF/IntroduceToREST.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        认识RESTful
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-IntroduceToDRF/HowToDesignREST.html">
            
                
                    <a href="../C01-IntroduceToDRF/HowToDesignREST.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        RESTful设计方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="C01-IntroduceToDRF/DevelopRESTAPIWithDjango.html">
            
                
                    <a href="../C01-IntroduceToDRF/DevelopRESTAPIWithDjango.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        使用Django开发REST接口
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="1.5" data-path="C01-IntroduceToDRF/CoreTaskToDevelopRESTAPI.html">
            
                
                    <a href="../C01-IntroduceToDRF/CoreTaskToDevelopRESTAPI.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        明确REST接口开发的核心任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="C01-IntroduceToDRF/AboutDRF.html">
            
                
                    <a href="../C01-IntroduceToDRF/AboutDRF.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        DjangoRESTframework简介
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-DRFProject/index.html">
            
                
                    <a href="../C02-DRFProject/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        DRF工程搭建
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-DRFProject/InstallAndConfig.html">
            
                
                    <a href="../C02-DRFProject/InstallAndConfig.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        环境安装与配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C02-DRFProject/TheFirstDRFProgram.html">
            
                
                    <a href="../C02-DRFProject/TheFirstDRFProgram.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        见识DRF的魅力
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Serializer/index.html">
            
                
                    <a href="../C03-Serializer/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Serializer序列化器
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Serializer/Declaring.html">
            
                
                    <a href="../C03-Serializer/Declaring.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        定义Serializer
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Serializer/Serializing.html">
            
                
                    <a href="../C03-Serializer/Serializing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        序列化使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Serializer/Deserializing.html">
            
                
                    <a href="../C03-Serializer/Deserializing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        反序列化使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Serializer/ModelSerializer.html">
            
                
                    <a href="../C03-Serializer/ModelSerializer.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        模型类序列化器ModelSerializer
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-View/index.html">
            
                
                    <a href="../C04-View/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        视图
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C04-View/RequestAndResponse.html">
            
                
                    <a href="../C04-View/RequestAndResponse.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        Request与Response
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C04-View/View.html">
            
                
                    <a href="../C04-View/View.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        视图概览
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-View/ViewIntroduction.html">
            
                
                    <a href="../C04-View/ViewIntroduction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        视图说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="C04-View/ViewSet.html">
            
                
                    <a href="../C04-View/ViewSet.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        视图集ViewSet
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="C04-View/Routers.html">
            
                
                    <a href="../C04-View/Routers.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        路由Router
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-Components/index.html">
            
                
                    <a href="../C05-Components/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        其他功能
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-Components/Authentication.html">
            
                
                    <a href="../C05-Components/Authentication.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        认证
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-Components/Permissions.html">
            
                
                    <a href="../C05-Components/Permissions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        权限
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="C05-Components/Throttling.html">
            
                
                    <a href="../C05-Components/Throttling.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        限流
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="C05-Components/Filtering.html">
            
                
                    <a href="../C05-Components/Filtering.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        过滤
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="C05-Components/Ordering.html">
            
                
                    <a href="../C05-Components/Ordering.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        排序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="C05-Components/Pagination.html">
            
                
                    <a href="../C05-Components/Pagination.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        分页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="C05-Components/Versioning.html">
            
                
                    <a href="../C05-Components/Versioning.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        版本
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="C05-Components/Exceptions.html">
            
                
                    <a href="../C05-Components/Exceptions.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="C05-Components/Documents.html">
            
                
                    <a href="../C05-Components/Documents.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        自动生成接口文档
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >课程介绍</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x660E;&#x786E;rest&#x63A5;&#x53E3;&#x5F00;&#x53D1;&#x7684;&#x6838;&#x5FC3;&#x4EFB;&#x52A1;">&#x660E;&#x786E;REST&#x63A5;&#x53E3;&#x5F00;&#x53D1;&#x7684;&#x6838;&#x5FC3;&#x4EFB;&#x52A1;</h1>
<p>&#x5206;&#x6790;&#x4E00;&#x4E0B;&#x4E0A;&#x8282;&#x7684;&#x6848;&#x4F8B;&#xFF0C;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#xFF0C;&#x5728;&#x5F00;&#x53D1;REST API&#x63A5;&#x53E3;&#x65F6;&#xFF0C;&#x89C6;&#x56FE;&#x4E2D;&#x505A;&#x7684;&#x6700;&#x4E3B;&#x8981;&#x6709;&#x4E09;&#x4EF6;&#x4E8B;&#xFF1A;</p>
<ul>
<li>&#x5C06;&#x8BF7;&#x6C42;&#x7684;&#x6570;&#x636E;&#xFF08;&#x5982;JSON&#x683C;&#x5F0F;&#xFF09;&#x8F6C;&#x6362;&#x4E3A;&#x6A21;&#x578B;&#x7C7B;&#x5BF9;&#x8C61;</li>
<li>&#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;</li>
<li>&#x5C06;&#x6A21;&#x578B;&#x7C7B;&#x5BF9;&#x8C61;&#x8F6C;&#x6362;&#x4E3A;&#x54CD;&#x5E94;&#x7684;&#x6570;&#x636E;&#xFF08;&#x5982;JSON&#x683C;&#x5F0F;&#xFF09;</li>
</ul>
<h2 id="&#x5E8F;&#x5217;&#x5316;serialization">&#x5E8F;&#x5217;&#x5316;Serialization</h2>
<p><a href="https://zh.wikipedia.org/wiki/%E5%BA%8F%E5%88%97%E5%8C%96" target="_blank">&#x7EF4;&#x57FA;&#x767E;&#x79D1;</a>&#x4E2D;&#x5BF9;&#x4E8E;&#x5E8F;&#x5217;&#x5316;&#x7684;&#x5B9A;&#x4E49;&#xFF1A;</p>
<p><strong>&#x5E8F;&#x5217;&#x5316;</strong>&#xFF08;serialization&#xFF09;&#x5728;&#x8BA1;&#x7B97;&#x673A;&#x79D1;&#x5B66;&#x7684;&#x8D44;&#x6599;&#x5904;&#x7406;&#x4E2D;&#xFF0C;&#x662F;&#x6307;&#x5C06;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x6216;&#x7269;&#x4EF6;&#x72B6;&#x6001;&#x8F6C;&#x6362;&#x6210;&#x53EF;&#x53D6;&#x7528;&#x683C;&#x5F0F;&#xFF08;&#x4F8B;&#x5982;&#x5B58;&#x6210;&#x6863;&#x6848;&#xFF0C;&#x5B58;&#x4E8E;&#x7F13;&#x51B2;&#xFF0C;&#x6216;&#x7ECF;&#x7531;&#x7F51;&#x7EDC;&#x4E2D;&#x4F20;&#x9001;&#xFF09;&#xFF0C;&#x4EE5;&#x7559;&#x5F85;&#x540E;&#x7EED;&#x5728;&#x76F8;&#x540C;&#x6216;&#x53E6;&#x4E00;&#x53F0;&#x8BA1;&#x7B97;&#x673A;&#x73AF;&#x5883;&#x4E2D;&#xFF0C;&#x80FD;&#x6062;&#x590D;&#x539F;&#x5148;&#x72B6;&#x6001;&#x7684;&#x8FC7;&#x7A0B;&#x3002;&#x4F9D;&#x7167;&#x5E8F;&#x5217;&#x5316;&#x683C;&#x5F0F;&#x91CD;&#x65B0;&#x83B7;&#x53D6;&#x5B57;&#x8282;&#x7684;&#x7ED3;&#x679C;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x5229;&#x7528;&#x5B83;&#x6765;&#x4EA7;&#x751F;&#x4E0E;&#x539F;&#x59CB;&#x7269;&#x4EF6;&#x76F8;&#x540C;&#x8BED;&#x4E49;&#x7684;&#x526F;&#x672C;&#x3002;&#x5BF9;&#x4E8E;&#x8BB8;&#x591A;&#x7269;&#x4EF6;&#xFF0C;&#x50CF;&#x662F;&#x4F7F;&#x7528;&#x5927;&#x91CF;&#x53C2;&#x7167;&#x7684;&#x590D;&#x6742;&#x7269;&#x4EF6;&#xFF0C;&#x8FD9;&#x79CD;&#x5E8F;&#x5217;&#x5316;&#x91CD;&#x5EFA;&#x7684;&#x8FC7;&#x7A0B;&#x5E76;&#x4E0D;&#x5BB9;&#x6613;&#x3002;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x7269;&#x4EF6;&#x5E8F;&#x5217;&#x5316;&#xFF0C;&#x5E76;&#x4E0D;&#x6982;&#x62EC;&#x4E4B;&#x524D;&#x539F;&#x59CB;&#x7269;&#x4EF6;&#x6240;&#x5173;&#x8054;&#x7684;&#x51FD;&#x5F0F;&#x3002;&#x8FD9;&#x79CD;&#x8FC7;&#x7A0B;&#x4E5F;&#x79F0;&#x4E3A;&#x7269;&#x4EF6;&#x7F16;&#x7EC4;&#xFF08;marshalling&#xFF09;&#x3002;&#x4ECE;&#x4E00;&#x7CFB;&#x5217;&#x5B57;&#x8282;&#x63D0;&#x53D6;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x7684;&#x53CD;&#x5411;&#x64CD;&#x4F5C;&#xFF0C;&#x662F;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#xFF08;&#x4E5F;&#x79F0;&#x4E3A;&#x89E3;&#x7F16;&#x7EC4;, deserialization, unmarshalling&#xFF09;&#x3002;</p>
<p><strong>&#x5E8F;&#x5217;&#x5316;</strong>&#x5728;&#x8BA1;&#x7B97;&#x673A;&#x79D1;&#x5B66;&#x4E2D;&#x901A;&#x5E38;&#x6709;&#x4EE5;&#x4E0B;&#x5B9A;&#x4E49;:</p>
<p>&#x200B;    &#x5728;&#x6570;&#x636E;&#x50A8;&#x5B58;&#x4E0E;&#x4F20;&#x9001;&#x7684;&#x90E8;&#x5206;&#x662F;&#x6307;&#x5C06;&#x4E00;&#x4E2A;<a href="https://zh.wikipedia.org/wiki/%E5%AF%B9%E8%B1%A1_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6" target="_blank">&#x5BF9;&#x8C61;</a>)&#x5B58;&#x50A8;&#x81F3;&#x4E00;&#x4E2A;<a href="https://zh.wikipedia.org/w/index.php?title=%E5%84%B2%E5%AD%98%E5%AA%92%E4%BB%8B&amp;action=edit&amp;redlink=1" target="_blank">&#x50A8;&#x5B58;&#x5A92;&#x4ECB;</a>&#xFF0C;&#x4F8B;&#x5982;<a href="https://zh.wikipedia.org/wiki/%E6%AA%94%E6%A1%88" target="_blank">&#x6863;&#x6848;</a>&#x6216;&#x662F;<a href="https://zh.wikipedia.org/w/index.php?title=%E8%A8%98%E5%84%84%E9%AB%94%E7%B7%A9%E8%A1%9D&amp;action=edit&amp;redlink=1" target="_blank">&#x8BB0;&#x4EBF;&#x4F53;&#x7F13;&#x51B2;</a>&#x7B49;&#xFF0C;&#x6216;&#x8005;&#x900F;&#x8FC7;&#x7F51;&#x7EDC;&#x4F20;&#x9001;&#x8D44;&#x6599;&#x65F6;&#x8FDB;&#x884C;&#x7F16;&#x7801;&#x7684;&#x8FC7;&#x7A0B;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;<a href="https://zh.wikipedia.org/wiki/%E5%AD%97%E8%8A%82" target="_blank">&#x5B57;&#x8282;</a>&#x6216;&#x662F;<a href="https://zh.wikipedia.org/wiki/XML" target="_blank">XML</a>&#x7B49;&#x683C;&#x5F0F;&#x3002;&#x800C;<a href="https://zh.wikipedia.org/wiki/%E5%AD%97%E8%8A%82" target="_blank">&#x5B57;&#x8282;</a>&#x7684;&#x6216;<a href="https://zh.wikipedia.org/wiki/XML" target="_blank">XML</a>&#x7F16;&#x7801;&#x683C;&#x5F0F;&#x53EF;&#x4EE5;&#x8FD8;&#x539F;&#x5B8C;&#x5168;&#x76F8;&#x7B49;&#x7684;<a href="https://zh.wikipedia.org/wiki/%E5%AF%B9%E8%B1%A1_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6" target="_blank">&#x5BF9;&#x8C61;</a>)&#x3002;&#x8FD9;&#x7A0B;&#x5E8F;&#x88AB;&#x5E94;&#x7528;&#x5728;&#x4E0D;&#x540C;<a href="https://zh.wikipedia.org/wiki/%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F" target="_blank">&#x5E94;&#x7528;&#x7A0B;&#x5E8F;</a>&#x4E4B;&#x95F4;&#x4F20;&#x9001;<a href="https://zh.wikipedia.org/wiki/%E5%AF%B9%E8%B1%A1_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6" target="_blank">&#x5BF9;&#x8C61;</a>)&#xFF0C;&#x4EE5;&#x53CA;&#x670D;&#x52A1;&#x5668;&#x5C06;<a href="https://zh.wikipedia.org/wiki/%E5%AF%B9%E8%B1%A1_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6" target="_blank">&#x5BF9;&#x8C61;</a>)&#x50A8;&#x5B58;&#x5230;<a href="https://zh.wikipedia.org/wiki/%E6%AA%94%E6%A1%88" target="_blank">&#x6863;&#x6848;</a>&#x6216;<a href="https://zh.wikipedia.org/wiki/%E8%B3%87%E6%96%99%E5%BA%AB" target="_blank">&#x6570;&#x636E;&#x5E93;</a>&#x3002;&#x76F8;&#x53CD;&#x7684;&#x8FC7;&#x7A0B;&#x53C8;&#x79F0;&#x4E3A;<a href="https://zh.wikipedia.org/w/index.php?title=%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96&amp;action=edit&amp;redlink=1" target="_blank"><strong>&#x53CD;&#x5E8F;&#x5217;&#x5316;</strong></a>&#x3002;</p>
<p>&#x7B80;&#x800C;&#x8A00;&#x4E4B;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;<strong>&#x5E8F;&#x5217;&#x5316;</strong>&#x7406;&#x89E3;&#x4E3A;&#xFF1A;</p>
<p><strong>&#x5C06;&#x7A0B;&#x5E8F;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x4E3A;&#x5176;&#x4ED6;&#x683C;&#x5F0F;&#xFF08;&#x5B57;&#x5178;&#x3001;JSON&#x3001;XML&#x7B49;&#xFF09;&#xFF0C;&#x4F8B;&#x5982;&#x5C06;Django&#x4E2D;&#x7684;&#x6A21;&#x578B;&#x7C7B;&#x5BF9;&#x8C61;&#x88C5;&#x6362;&#x4E3A;JSON&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x8FD9;&#x4E2A;&#x8F6C;&#x6362;&#x8FC7;&#x7A0B;&#x6211;&#x4EEC;&#x79F0;&#x4E3A;&#x5E8F;&#x5217;&#x5316;&#x3002;</strong></p>
<p>&#x5982;&#xFF1A;</p>
<pre><code class="lang-python">queryset = BookInfo.objects.all()
book_list = []
<span class="hljs-comment"># &#x5E8F;&#x5217;&#x5316;</span>
<span class="hljs-keyword">for</span> book <span class="hljs-keyword">in</span> queryset:
    book_list.append({
        <span class="hljs-string">&apos;id&apos;</span>: book.id,
        <span class="hljs-string">&apos;btitle&apos;</span>: book.btitle,
        <span class="hljs-string">&apos;bpub_date&apos;</span>: book.bpub_date,
        <span class="hljs-string">&apos;bread&apos;</span>: book.bread,
        <span class="hljs-string">&apos;bcomment&apos;</span>: book.bcomment,
        <span class="hljs-string">&apos;image&apos;</span>: book.image.url <span class="hljs-keyword">if</span> book.image <span class="hljs-keyword">else</span> <span class="hljs-string">&apos;&apos;</span>
    })
<span class="hljs-keyword">return</span> JsonResponse(book_list, safe=<span class="hljs-keyword">False</span>)
</code></pre>
<p><strong>&#x53CD;&#x4E4B;&#xFF0C;&#x5C06;&#x5176;&#x4ED6;&#x683C;&#x5F0F;&#xFF08;&#x5B57;&#x5178;&#x3001;JSON&#x3001;XML&#x7B49;&#xFF09;&#x8F6C;&#x6362;&#x4E3A;&#x7A0B;&#x5E8F;&#x4E2D;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x4F8B;&#x5982;&#x5C06;JSON&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x6362;&#x4E3A;Django&#x4E2D;&#x7684;&#x6A21;&#x578B;&#x7C7B;&#x5BF9;&#x8C61;&#xFF0C;&#x8FD9;&#x4E2A;&#x8FC7;&#x7A0B;&#x6211;&#x4EEC;&#x79F0;&#x4E3A;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x3002;</strong></p>
<p>&#x5982;&#xFF1A;</p>
<pre><code class="lang-python">json_bytes = request.body
json_str = json_bytes.decode()

<span class="hljs-comment"># &#x53CD;&#x5E8F;&#x5217;&#x5316;</span>
book_dict = json.loads(json_str)
book = BookInfo.objects.create(
    btitle=book_dict.get(<span class="hljs-string">&apos;btitle&apos;</span>),
    bpub_date=datetime.strptime(book_dict.get(<span class="hljs-string">&apos;bpub_date&apos;</span>), <span class="hljs-string">&apos;%Y-%m-%d&apos;</span>).date()
)
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;<strong>&#x5728;&#x5F00;&#x53D1;REST API&#x65F6;&#xFF0C;&#x89C6;&#x56FE;&#x4E2D;&#x8981;&#x9891;&#x7E41;&#x7684;&#x8FDB;&#x884C;&#x5E8F;&#x5217;&#x5316;&#x4E0E;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x7684;&#x7F16;&#x5199;&#x3002;</strong></p>
<h2 id="&#x603B;&#x7ED3;">&#x603B;&#x7ED3;</h2>
<p>&#x5728;&#x5F00;&#x53D1;REST API&#x63A5;&#x53E3;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x5728;<strong>&#x89C6;&#x56FE;</strong>&#x4E2D;&#x9700;&#x8981;&#x505A;&#x7684;&#x6700;&#x6838;&#x5FC3;&#x7684;&#x4E8B;&#x662F;&#xFF1A;</p>
<ul>
<li><p><strong>&#x5C06;&#x6570;&#x636E;&#x5E93;&#x6570;&#x636E;&#x5E8F;&#x5217;&#x5316;&#x4E3A;&#x524D;&#x7AEF;&#x6240;&#x9700;&#x8981;&#x7684;&#x683C;&#x5F0F;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#xFF1B;</strong></p>
</li>
<li><p><strong>&#x5C06;&#x524D;&#x7AEF;&#x53D1;&#x9001;&#x7684;&#x6570;&#x636E;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x4E3A;&#x6A21;&#x578B;&#x7C7B;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x4FDD;&#x5B58;&#x5230;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x3002;</strong></p>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../C01-IntroduceToDRF/DevelopRESTAPIWithDjango.html" class="navigation navigation-prev " aria-label="Previous page: 使用Django开发REST接口"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../C01-IntroduceToDRF/AboutDRF.html" class="navigation navigation-next " aria-label="Next page: DjangoRESTframework简介"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
